package com.duan.activitytest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class SecondActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second_layout);

        //接收FA传递的数据
        //Intent intent = getIntent();
        //String data = intent.getStringExtra("extra_data");
        //Log.e("SecondActivity",data);

        //添加返回数据的逻辑
        Button button2 = (Button) findViewById(R.id.button_2);
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(SecondActivity.this,FirstActivity.class);
                startActivity(intent);

                //Intent intent = getIntent();
                //intent.putExtra("data_return","Hello FirstActivity");
                //setResult(RESULT_OK,intent);
                //finish();
            }

        });
    }
    @Override
    public void onBackPressed() {
        //super.onBackPressed();
        Intent intent = new Intent();
        intent.putExtra("data_return","Hello FirstActivity");
        setResult(RESULT_OK,intent);
        finish();
    }
}